#include "../netfwd.h"

#define PATH_BUF_LEN	256
#define RM_CMD			256

void rm_shopchannel( const char * busip, int32_t trade_id )
{
	char path_buf[PATH_BUF_LEN] = {0};
	int32_t key = ftok( getcwd( path_buf, PATH_BUF_LEN ), trade_id );
	struct in_addr in;
	inet_aton( busip, &in );
	key += in.s_addr;
	
	char cmd[RM_CMD] = {0};
	snprintf( cmd, RM_CMD, "ipcrm -M 0x%08x", key );
	fprintf( stderr, "%s\n", cmd );
	system( cmd );
	return;
}

int32_t main( uint32_t argc, char * argv[] )
{
	if( argc != 3 )
	{
		fprintf( stderr, "usage: rm_shopchannel busid trade_count\n" );
		return 0;
	}
	
	int32_t trade_count = strtol( argv[2], NULL, 10 );
		
	for( int32_t index = 0; index < trade_count; ++index )
	{
		rm_shopchannel( argv[1], index );
	}
	return 0;
}
